package com.example.fw;

import org.openqa.selenium.By;

public class NavigationiHelper extends MainHelper {

	public NavigationiHelper(ApplicationManager appManager) {
		super(appManager);
	}

	public void openMainPage() {
		if(! onMainPage()){
			click(By.linkText("home"));
		}
	}

	private boolean onMainPage() {
		return (driver.findElements(By.id("maintable")).size() > 0);
	}

	public void clickOnAddNewButton() {
		driver.findElement(By.linkText("add new")).click();
	}

	public void submitNewCreation() {
		driver.findElement(By.name("submit")).click();
	}
	
	public void openGroupsPage() {
		if(! onGroupsPage()){
		click(By.linkText("groups"));
		}
	}

	private boolean onGroupsPage() {
		if(driver.getCurrentUrl().contains("/group.php") 
				&& driver.findElements(By.xpath("//input[@value='New group']")).size() > 0){
			return true;
		} else {
			return false;
		}
	}

}
